import { logout } from '@/api/login'
/**
 * 注销登录状态
 */
export async function handleLogout() {
  try {
    await logout()
    // 清空登录状态
    // 跳转到登录页
    sessionStorage.setItem('_csrf_', '')
    sessionStorage.clear()
    localStorage.clear()
    const { origin, pathname, search } = window.location || {}
    const callbackUrl = origin + pathname + encodeURIComponent(search)
    if (pathname !== '/user/login') {
      // homePage为true为主动退出默认回到首页
      window.location.href = '/user/login?callbackUrl=' + callbackUrl
    }
  } catch (error) {
    console.error('注销失败', error)
  }
}
